MySQL - Using Join
JOINS are used to combine rows from two or more tables, based on a related column between those tables. The following are the types of joins:
SYNTAX :
SELECT columns
FROM table1
JOIN_NAME table2
ON table1.column = table2.column;
LEFT join returns records from the left table, and also those records which satisfy the condition from the right table.
EXAMPLE :
SELECT a.StudentName,a.Studentclass,b.Studentmarks
FROM Studentinfo as a
LEFT JOIN Studentmarks as b ON a.StudentID
StudentName | Studentclass | Studentmarks |
---|---|---|
Manjusha | sixth | 500 |
Manjusha | sixth | 465 |
Manjusha | sixth | 520 |
Manjusha | sixth | 450 |
Noothan | sixth | 500 |
Noothan | sixth | 465 |
Noothan | sixth | 520 |
Noothan | sixth | 450 |
Meherish | sixth | 500 |
Meherish | sixth | 465 |
Meherish | sixth | 520 |
Meherish | sixth | 450 |
Ajaashi | tenth | 500 |
Ajaashi | tenth | 465 |
Ajaashi | tenth | 520 |
Ajaashi | tenth | 450 |
Sahayana | sixth | 500 |
Sahayana | sixth | 465 |
Sahayana | sixth | 520 |
Sahayana | sixth | 450 |
Sweekrutha | sixth | 500 |
Sweekrutha | sixth | 465 |
Sweekrutha | sixth | 520 |
Sweekrutha | sixth | 450 |
RIGHT join returns records from the right table, and also those records which satisfy the condition from the left table.
SYNTAX :
SELECT a.StudentName,a.Studentclass,b.Studentmarks
FROM Studentinfo as a
RIGHT JOIN Studentmarks as b ON a.StudentID
StudentName | Studentclass | Studentmarks |
---|---|---|
Manjusha | sixth | 500 |
Noothan | sixth | 500 |
Meherish | sixth | 500 |
Ajaashi | tenth | 500 |
Sahayana | sixth | 500 |
Sweekrutha | sixth | 500 |
manju | sixth | 500 |
Manjusha | sixth | 500 |
Noothan | sixth | 500 |
Meherish | sixth | 500 |
Ajaashi | tenth | 500 |
Sahayana | sixth | 500 |
Sweekrutha | sixth | 500 |
manju | sixth | 500 |
Manjusha | sixth | 465 |
Noothan | sixth | 465 |
Meherish | sixth | 465 |
Ajaashi | tenth | 465 |
Sahayana | sixth | 465 |
Sweekrutha | sixth | 465 |
manju | sixth | 465 |
Manjusha | sixth | 520 |
Noothan | sixth | 520 |
Meherish | sixth | 520 |
Ajaashi | tenth | 520 |
Sahayana | sixth | 520 |
Sweekrutha | sixth | 520 |
manju | sixth | 520 |
Manjusha | sixth | 450 |
Noothan | sixth | 450 |
Meherish | sixth | 450 |
Ajaashi | tenth | 450 |
Sahayana | sixth | 450 |
Sweekrutha | sixth | 450 |
manju | sixth | 450 |
This join returns those records which have matching values in both the tables.
EXAMPLE :
SELECT studentrecord.StudentID, Studentinfo.StudentName
FROM studentrecord
INNER JOIN studentinfo ON studentrecord.StudentId = studentinfo.StudentId;
StudentID | StudentName |
---|---|
1 | Manjusha |
2 | Noothan |
This join returns all those records which either have a match in the left or the right table.
SYNTAX :
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;
MySQL - Grant_ Revoke Privilege
posted on 2019-11-26 23:15:04 - mysql Tutorials